<template>
	<view class="">
		<view class="box">
			<view class="boxitem" v-for="item in list" :key="item.id">
				<image :src="item.choosed_image" mode="aspectFill"></image>
				<view class="name">
					{{item.name}}
				</view>
				<view class="btn" @click="use(item.id)"  >
					使用
				</view>
			</view>
			
		</view>
		<view class="tips">
			更多红包封面即将来袭~
		</view>
	</view>
</template>

<script>
	import {templateList,templateUse} from "../../api/red.js"
	export default {
		data(){
			return{
				list:[]
			}
		},
		onLoad() {
			this.getlist()
		},
		
		methods:{
			use(id){
				templateUse({
					template_id:id
				}).then(res=>{
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
					uni.$u.toast(res.msg)
				})
			},
			getlist(){
				templateList().then(res=>{
					this.list=res.data
				})
			}
		}
	}
</script>

<style lang="scss">
	.box {
		width: 750rpx;
		display: flex;
		flex-wrap: wrap;
		

	}

	.boxitem {
		width: 330rpx;
		height: 630rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin-top: 20rpx;
		display: flex;
		// justify-content: center;
		align-items: center;
		flex-direction: column;
		margin: 22rpx;
		padding-bottom: 20rpx;
		>image {
			width: 306rpx;
			height: 510rpx;
			margin-top: 12rpx;
		}
	}

	.name {
		margin: 0 auto;
		width: 306rpx;
		height: 40rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		text-align: center;
		margin-top: 24rpx;
		font-weight: 400;
		font-size: 30rpx;
		color: #3D3D3D;
	}
	.btn{
		width: 158rpx;
		height: 60rpx;
		background: #FF5959;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
		text-align: center;
		line-height: 60rpx;
		font-weight: 500;
		font-size: 26rpx;
		color: #FFFFFF;
		margin-top: 14rpx;
	}
	.tips{
		width: 750rpx;
		text-align: center;
		margin-top: 356rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
	}
</style>